package com.itheima.Jiuye13;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class LockDemo implements Runnable{
    private int a = 100;
    private Lock lock = new ReentrantLock();
    @Override
    public void run() {
            while (true){
        try {
                lock.lock();
                if (a <= 0){
                    break;
                }else {
                    a--;
                    System.out.println(Thread.currentThread().getName()+"在卖票，还有"+a+"张票");
                }
        } finally {
                lock.unlock();
            }
            break;
        }
    }
}
